#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;

int a[11]={1,7,23,32,34,43,45,234,433,435,456};

int binarysearch(int start,int end,int key)
{
	int low=start,high=end;
	while(low<=high)
	{
		int mid=(low+high)/2;
		if(key>a[mid])
		{
			low=mid+1;
		}
		else if(key<=a[mid])
		{
			high=mid-1;
		}
	}
	return high;
}

int main()
{
	sort(a,a+sizeof(a)/4);
	for(int i=0;i<sizeof(a)/4;i++)
	{
		cout << a[i] << " ";
	}
	cout << endl;
	int t;
	cin >> t;
	while(t--)
	{
		int key;
		cin >> key;
		cout << binarysearch(0,sizeof(a)/4-1,key) << endl;
	}

	return 0;
}

